<?php
if(!defined('BZ_XTBLOG') || !defined('BZ_WJSCUZ')) {
	exit('Access Denied');
}
$fid =verify_id($_GET['fid']);
$hftsname=$_GET['name'];
$act =$_GET['act'];
$forum=$db->get_one('forum'," `id` ='$fid' AND `sz_sc` ='0'",'');
$forumlt=$db->get_one('forum_class'," `id` ='$forum[cid]'",'');
$wzxx_title =$forum[name].'-查看帖子-'.$wzxx_title.'';
$wzxx_gj    =$forum[name].'-查看帖子-'.$wzxx_gj.'';
$wzxx_ms    =$forum[name].'-查看帖子-'.$wzxx_ms.'';
$user_czqx=$user_class->user_qx('forum',$forum[id],$user_uid);
     $ltid  =$forumlt[id];
     $ltname=$forumlt[name];
if(!$forumlt[id]){
	  $pdid="1";
}else if(!$forum[id]){
	  $pdid="2";
}else if($forum[type_lx] == '2' && !$user_uid){
	  $pdid="3";
}else{
	$content='';
  if(Bingz_cache_html('forum','forum_'.$forum[id].'','1') && Bingz_config('forum_config_hchtmk') == '1'){
	  $content=Bingz_cache_html('forum','forum_'.$forum[id].'','1');
  }else{
    $content=$ubb->content_ubb($forum[content]);
    ####################################################################帖子附件
    if(preg_match_all("/\[attach\]([0-9]{1,9})\[\/attach\]/",$content,$sms)){
     foreach( $sms[1] as $a => $val){
	    $smsa="[attach]".$val."[/attach]";
      if($wzfj=$db->get_one('forum_data'," `uid` = '$forum[uid]' AND `id` = '$val'",'')){
        if($wzfj[fid] == '0' or $wzfj[fid] == $forum[id] ){
        	$db->update('forum_data',array( 'paixi' => $a ),"`id` ='$wzfj[id]'");
          $wjlxtp=attachtype($wzfj[fjlx]);
          if( $wzfj[money] > '0' && !$db->get_one('forum_data_user'," `uid` = '$user_uid' AND `fid` = '$wzfj[id]'",'') && $user_czqx < '10' && $forum[uid] != $user_uid ){
            $wzbbsfj="<div class=\"forum_xz\"><b>$wjlxtp $wzfj[name]</b><font color=\"#999999\"> ($wzfj[size] KB, 购买次数: $wzfj[gmcs])</font><br/>(查看或下载)需要支付$wzxx_jb_name ：<font color='#FF8E44'>$wzfj[money]</font> (<a href=\"index.php?{$Bingz_ml}=forum&{$Bingz_md}=attachment&act=gm&fid=$wzfj[id]\" >确定支付</a>)</div>";
          }else{
        		if($wzfj[fjgs]=='1'){
               $wzbbsfj='<div style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;text-align:center;"><a href="index.php?'.$Bingz_ml.'=forum&'.$Bingz_md.'=attachment&act=ck&fid='.$wzfj[id].'" ><img src="data/forum/'.$wzfj[url].'" alt="'.$wzfj[name].'" /></a></div>';
               $db->update('forum_data',array( 'gmcs' => '+1' ),"`id` ='$wzfj[id]' ");
               if($wzfj[fid] == '0'){
                  $db->update('forum',array( 'type' => 3 ),"`id` ='$forum[id]' AND `type` = '0' ");
                  $db->update('forum_data',array( 'fid' => $forum[id] ),"`id` ='$wzfj[id]'");
               }
            }else{
               $wzbbsfj="<div class=\"forum_xz\"><b>$wjlxtp $wzfj[name]</b><font color=\"#999999\"> ($wzfj[size] KB, 下载: $wzfj[xzcs])</font><br/> (<a href=\"index.php?{$Bingz_ml}=forum&{$Bingz_md}=attachment&fid=$wzfj[id]\" >下载资源</a>)</div>";
               if($wzfj[fid] == '0'){
                  $db->update('forum',array( 'type' => 4 ),"`id` ='$forum[id]' AND `type` = '0' ");
                  $db->update('forum_data',array( 'fid' => $forum[id] ),"`id` ='$wzfj[id]'");
               }
            }
          }
        }
      }
        $content=str_replace($smsa,$wzbbsfj,$content);
        $wzbbsfj='';
     }
    }
    if(Bingz_config('forum_config_hchtmk') == '1'){Bingz_cache_html_post('forum','forum_'.$forum[id].'',$content);}
  }
####################################################################帖子数据
    $forum_name=Bingz_html($forum[name]);
    if($forum[nameys] == '0'){
	     $forum_name=$forum_name;
	  }else{
	     $forum_name='<font color="'.$forum[nameys].'">'.$forum_name.'</font>';
    }
    $forum_id     =$forum[id];
    $forum_content=$content;//内容
    $forum_din    =$forum[type_din];//顶
    $forum_suo    =$forum[type_suo];//锁
    $forum_jin    =$forum[type_jin];//金
    $forum_cun    =$forum[cun];//推
    $forum_sj     =Bingz_time($forum[time_b]);//时间
    $forum_hfs    =$forum[hfs];//回复
    $forum_cks    =$forum[cks];//查看
    $forum_lx     =$forum[type];//类型
    $forum_tpsz   =$forum[type_tp_gb];
     if($forum[type_tp_gb] == '0' && $forum[type_tp_sj] > '0'){
     	  if($time > $forum[type_tp_sj] ){
     	  	$db->update('forum',array('type_tp_gb' => '1' ),"`id` ='$forum_id'");
     	  	$forum_tpsz='1';
     	  }
     }
     $gtpid=$db->num_rows('forum_polloption_user',"`tid` ='$forum_id' ",'id');
     $topsol=$db->query('forum_polloption'," `tid` ='$forum[id]' ORDER BY `id` ",'');
     $a='1';
     while($pp=mysql_fetch_array($topsol)){
     	  $tsid=$db->num_rows('forum_polloption_user',"`tid` ='$forum_id' AND `tpid` ='$pp[id]' ",'id');
	      $topsj[]= array('aid' => $a ,'tsid' => $tsid ,'id' => $pp[id] ,'name' => $pp[name] );
	      $a++;
     }

    if($forum[type_lx] == '1' && !$db->get_one('forum_hui',"`uid` ='$user_uid' AND `fid` ='$forum[id]' ",'')){
  	   $forum_type_yc='1';
    }
		   if($forum['type']=='1'){
		      $typea='投票';
	     }else if($forum['type']=='2'){
		      $typea='悬赏';
	     }else if($forum['type']=='3'){
		      $typea='图片';
		      $typeaa='<img src="images/forum/data_tp.gif" alt="图片"/>';
	     }else if($forum['type']=='4'){
		      $typea='附件';
		      $typeaa='<img src="images/forum/data_fj.gif" alt="附件"/>';
	     }else if($forum['type']=='5'){
		      $typea='派币';
       }
    $lz_uid       =$forum[uid];
    $lz_name      =$user_class->user_name($forum[uid]);
    $lz_namej     =$user_class->user_name($forum[uid],'1');
    $lz_namesz    =$forum[sz_lm];
    $lz_tx        =$user_class->user_tx($forum[uid]);
    $lz_qm        =$user_class->user_qm($forum[uid]);
###################################################################帖子回复
if(Bingz_config('forum_config_suanx') != '1'){
	   $_GET['hfp'] ='dx';
}
if($_GET['hfp'] == 'dx'){
   $num_count=$db->num_rows('forum_hui'," `fid` ='$forum[id]' ",'id');
   $list_num ='5';
   $num_start=page_num($list_num,$num_count);
   $sql_hui  =$db->query('forum_hui'," `fid` ='$forum[id]' ORDER BY `id` DESC LIMIT ".$num_start." , ".$list_num." ",'');
}else{
   $num_count=$db->num_rows('forum_hui'," `fid` ='$forum[id]' ",'id');
   $list_num ='5';
   $num_start=page_num($list_num,$num_count);
   $sql_hui  =$db->query('forum_hui'," `fid` ='$forum[id]' ORDER BY `id` LIMIT ".$num_start." , ".$list_num." ",'');
}  
   $hhts='1';
   if($_GET['page'] > '1' ){
      $hhts=(($_GET['page']-1)*$list_num)+1;
      $num_start=$num_count-(($_GET['page']-1)*$list_num);
	 }else{
      $num_start=$num_count;
	 }
   while($row=mysql_fetch_array($sql_hui)){
	      $hytx=$user_class->user_tx($row[uid]);
	      $hyname=$user_class->user_name($row[uid]);
        $hynamej=$user_class->user_name($row[uid],'1');
	      $content=$ubb->content_ubb($row[content]);
        if(preg_match_all("/\[attach\]([0-9]{1,9})\[\/attach\]/",$content,$sms)){
           foreach( $sms[1] as $a => $val){
	         $smsa="[attach]".$val."[/attach]";
           if($wzfj=$db->get_one('forum_data',"`id` = '$val'",'')){
        	    $db->update('forum_data',array( 'paixi' => $a ),"`id` ='$wzfj[id]'");
              $wjlxtp=attachtype($wzfj[fjlx]);
              if( $wzfj[money] > '0' && !$db->get_one('forum_data_user'," `uid` = '$user_uid' AND `fid` = '$wzfj[id]'",'') && $user_czqx < '10' && $forum[uid] != $user_uid ){
                  $wzbbsfj="<div class=\"forum_xz\"><b>$wjlxtp $wzfj[name]</b><font color=\"#999999\"> ($wzfj[size] KB, 购买次数: $wzfj[gmcs])</font><br/>(查看或下载)需要支付$wzxx_jb_name ：<font color='#FF8E44'>$wzfj[money]</font> (<a href=\"index.php?{$Bingz_ml}=forum&amp;{$Bingz_md}=attachment&amp;act=gm&amp;fid=$wzfj[id]\" >确定支付</a>)</div>";
              }else{
        		      if($wzfj[fjgs]=='1'){
                     $wzbbsfj='<div style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;text-align:center;"><a href="index.php?'.$Bingz_ml.'=forum&'.$Bingz_md.'=attachment&act=ck&fid='.$wzfj[id].'" ><img src="data/forum/'.$wzfj[url].'" alt="'.$wzfj[name].'"  width="250" height="200" /></a></div>';
                     $db->update('forum_data',array( 'gmcs' => '+1' ),"`id` ='$wzfj[id]' ");
                     if($wzfj[fid] == '0'){
                        $db->update('forum',array( 'type' => 3 ),"`id` ='$forum[id]' AND `type` = '0' ");
                        $db->update('forum_data',array( 'fid' => $forum[id] ),"`id` ='$wzfj[id]'");
                     }
                  }else{
                     $wzbbsfj="<div class=\"forum_xz\"><b>$wjlxtp $wzfj[name]</b><font color=\"#999999\"> ($wzfj[size] KB, 下载: $wzfj[xzcs])</font><br/> (<a href=\"index.php?{$Bingz_ml}=forum&amp;{$Bingz_md}=attachment&amp;fid=$wzfj[id]\" >下载资源</a>)</div>";
                     if($wzfj[fid] == '0'){
                        $db->update('forum',array( 'type' => 4 ),"`id` ='$forum[id]' AND `type` = '0' ");
                        $db->update('forum_data',array( 'fid' => $forum[id] ),"`id` ='$wzfj[id]'");
                     }
                  }
              }

           }
           $content=str_replace($smsa,$wzbbsfj,$content);
           $wzbbsfj='';
           }
        }
	      $hui_xsts='';
        if( $forum[type_xs_hfid] == $row[id] ){
               $hui_xsts='1';
	      }
	      $hui_dsts='';
        if( $row[type_xs_hy] == '2' ){
               $hui_dsts='1';
	      }
        if($forum_xssz == '1' && $forum[uid] != $row[uid] && ( $forum[uid] == $user_uid or $forum_glqx)){
               $hui_xs='1';
	      }
        if($forum[uid] == $user_uid && $forum[uid] != $row[uid] ){
               $hui_ds='1';
	      }

#####################判断
        if( ($forum[time_b]+(60*60*24*30)) > $time && ($forum_ltbz or $user[hyqx] > '502') ){
        	   $forum_glqx='1';
        }
	      if($forum_ltbz or $user[hyqx] > '502' ){
             $hui_gl='1';
	      }
	       $pbpd='';
	      if($row[gl] > '0'){
	         if($forum_ltbz or $user[hyqx] > '502' ){
	      	     $pbpd='1';
	      	 }else{
	      	  	 $pbpd='2';
	      	 }
	      }
#####################
        $hflzts='';
        $zzsja=Bingz_time($row[time_a]);
        if($_GET['hfp'] == 'dx'){
        if($num_start == '1'){
           $hfpxts='<font color="#FF0000">沙发</font>';
           $hfpxtsts=$num_start.'楼';
        }elseif($num_start == '2'){
           $hfpxts='<font color="#D9D900">椅子</font>';
           $hfpxtsts=$num_start.'楼';
        }elseif($num_start == '3'){
           $hfpxts='<font color="#80FF00">凳子</font>';
           $hfpxtsts=$num_start.'楼';
        }else{
           $hfpxts=''.$num_start.'楼';
           $hfpxtsts=$num_start.'楼';
        }
        }else{
        if($hhts == '1'){
           $hfpxts='<font color="#FF0000">沙发</font>';
           $hfpxtsts=$hhts.'楼';
        }elseif($hhts == '2'){
           $hfpxts='<font color="#D9D900">椅子</font>';
           $hfpxtsts=$hhts.'楼';
        }elseif($hhts == '3'){
           $hfpxts='<font color="#80FF00">凳子</font>';
           $hfpxtsts=$hhts.'楼';
        }else{
           $hfpxts=''.$hhts.'楼';
           $hfpxtsts=$hhts.'楼';
        }
        }
        if($forum[uid] == $row[uid] && $forum[sz_lm]=='0'){
        	 $hflzts='<font color="#FF0000">楼主</font>';
        }
        if($row[type_hfid] > '0'){
        		 $bbs_hui=$db->get_one('forum_hui',"`id` ='$row[type_hfid]'",'');
	           $hfycontent=$ubb->content_ubb($bbs_hui[content]);
        if(preg_match_all("/\[attach\]([0-9]{1,9})\[\/attach\]/",$hfycontent,$sms)){
           foreach( $sms[1] as $a => $val){
	         $smsa="[attach]".$val."[/attach]";
           if($wzfj=$db->get_one('forum_data',"`id` = '$val'",'')){
        	    $db->update('forum_data',array( 'paixi' => $a ),"`id` ='$wzfj[id]'");
              $wjlxtp=attachtype($wzfj[fjlx]);
              if( $wzfj[money] > '0' && !$db->get_one('forum_data_user'," `uid` = '$user_uid' AND `fid` = '$wzfj[id]'",'') && $user_czqx < '10' && $forum[uid] != $user_uid ){
                  $wzbbsfj="<div class=\"forum_xz\"><b>$wjlxtp $wzfj[name]</b><font color=\"#999999\"> ($wzfj[size] KB, 购买次数: $wzfj[gmcs])</font><br/>(查看或下载)需要支付$wzxx_jb_name ：<font color='#FF8E44'>$wzfj[money]</font> (<a href=\"index.php?{$Bingz_ml}=forum&amp;{$Bingz_md}=attachment&amp;act=gm&amp;fid=$wzfj[id]\" >确定支付</a>)</div>";
              }else{
        		      if($wzfj[fjgs]=='1'){
                     $wzbbsfj='<div style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;text-align:center;"><a href="index.php?'.$Bingz_ml.'=forum&'.$Bingz_md.'=attachment&act=ck&fid='.$wzfj[id].'" ><img src="data/forum/'.$wzfj[url].'" alt="'.$wzfj[name].'"  width="250" height="200" /></a></div>';
                     $db->update('forum_data',array( 'gmcs' => '+1' ),"`id` ='$wzfj[id]' ");
                     if($wzfj[fid] == '0'){
                        $db->update('forum',array( 'type' => 3 ),"`id` ='$forum[id]' AND `type` = '0' ");
                        $db->update('forum_data',array( 'fid' => $forum[id] ),"`id` ='$wzfj[id]'");
                     }
                  }else{
                     $wzbbsfj="<div class=\"forum_xz\"><b>$wjlxtp $wzfj[name]</b><font color=\"#999999\"> ($wzfj[size] KB, 下载: $wzfj[xzcs])</font><br/> (<a href=\"index.php?{$Bingz_ml}=forum&amp;{$Bingz_md}=attachment&amp;fid=$wzfj[id]\" >下载资源</a>)</div>";
                     if($wzfj[fid] == '0'){
                        $db->update('forum',array( 'type' => 4 ),"`id` ='$forum[id]' AND `type` = '0' ");
                        $db->update('forum_data',array( 'fid' => $forum[id] ),"`id` ='$wzfj[id]'");
                     }
                  }
              }

           }
           $hfycontent=str_replace($smsa,$wzbbsfj,$hfycontent);
           $wzbbsfj='';
           }
        }
        		 $zzname=$user_class->user_name($bbs_hui[uid]);
        }
        $forum_hui[]= array("hflzts"=>"$hflzts","hfpx"=>"$hfpxts","pbpd"=>"$pbpd","hfpxts"=>"$hfpxtsts","hui_xs"=>"$hui_xs","hui_xsts"=>"$hui_xsts","hui_gl"=>"$hui_gl","hui_glsz"=>"$row[gl]","content"=>"$content","hui_sj"=>"$zzsja","hyuid"=>"$row[uid]","hytx"=>"$hytx","hyname"=>"$hyname","hynamej"=>"$hynamej","id"=>"$row[id]",
        "hfmsz"=>"$row[type_hfid]","hfmts"=>"$row[type_hfts]","hfmcontent"=>"$hfycontent","hymuid"=>"$bbs_hui[uid]","hymname"=>"$zzname","hui_ds"=>"$hui_ds","hui_dsts"=>"$hui_dsts");
        $num_start=$num_start-1;
        $hhts++;
   }
     $page=page_link($list_num,$num_count,'index.php?'.$bzml.'=forum&amp;'.$bzmd.'=viewthread&amp;hfp='.$_GET[hfp].'&amp;fid='.$forum[id].$bzsid.'');
}
$pageb=$_GET['page'];
$db->update('forum',array('cks' => '+1' ),"`id` ='$forum[id]'");
@include template('head');
@include template('forum/forum_viewthread');
@include template('foot');
?>